names = {"Peter","Paul","Mary"}
grades = {Mary = 10,Paul = 7, Peter = 8}
table.sort(names,function (n1,n2)
	return grades[n1] > grades[n2]
end )
function sortbygrade(names,grades)
	table.sort(names,function(n1,n2)
		return grades[n1] > grades[n2]
	end)
end

print(names[1])

function newCounter()
	local i = 0
	return function()
		i = i+1
		return i
	end
end

c1 = newCounter()
print(c1())
print(c1())
c2 = newCounter()
print(c2())
print(c1())

do
	local olOpen = io.open
	io.open = function(filename,mode)
		if access_OK(filename,mode) then
			return oldOpen(filename,mode)
		else
			return nil,"access denied"
		end
	end
end

io.open("helloworld",nil)
